<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>Home</title>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"/>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
        <a class="navbar-brand" href="#">Title</a>
        <ul class="nav navbar-nav">
            <li class="active">
                <a href="#">Home</a>
            </li>
        </ul>
    </div>
</nav>

<div class="container" style="margin-top: 80px;" ng-app="mylist" ng-controller="ctrl">
    <div class="panel panel-default">
        <div class="panel-body">
            <form action="" method="POST" role="form">
                <legend>INSERT</legend>

                <div class="form-group">
                    <label for="">Name</label>
                    <input type="text" data-ng-model="info.userName" class="form-control" id="" placeholder="Insert Name"/>
                </div>

                <div class="form-group">
                    <label for="">Password</label>
                    <input type="text" class="form-control" data-ng-model="info.password" id="" placeholder="Insert Password"/>
                </div>
                <div class="form-group">
                    <label for="">Email</label>
                    <input type="text" class="form-control" data-ng-model="info.email" id="" placeholder="Inser email"/>
                </div>
                <button type="button" class="btn btn-primary" data-ng-click="add()">Submit</button>
            </form>
        </div>
    </div>
    <label for="">Search:</label>
    <input type="text" name="" data-ng-model="Key" id="input" class="form-control" value="" placeholder="key words" pattern="" title=""/>

    <table class="table table-striped table-hover table-condensed">
        <thead>
        <th>Index</th>
        <th>Name</th>
        <th>Password</th>
        <th>Email</th>
        <th>Option</th>
        </thead>
        <tbody>
        <tr ng-repeat="x in dataList">
            <td>{{$index+1}}</td>
            <td>{{x.userName}}</td>
            <td>{{x.password}}</td>
            <td>{{x.email}}</td>
            <td><button type="button" class="btn btn-link" ng-click="del(x.id,$index)">删除</button></td>
        </tr>
        </tbody>
    </table>
</div>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script type="text/javascript">
    var app = angular.module("mylist", []);
    app.controller("ctrl",function($scope,$http){
        $scope.title = 'Name';
        $scope.desc = 0;

        $http.get("/api/user").success(function(response) {$scope.dataList = response;});

        $scope.add = function() {
            if ($scope.info!=null) {
                $http({
                    url:'/api/user',
                    method: 'POST',
                    data: $scope.info,
                }).success(function(){
                    $scope.dataList.push($scope.info);
                    $scope.info=null;

                }).error(function(){
                });
            }
        };

        $scope.del=function(id,index){
            $scope.dataList.splice(index,1);
            $http.get("/api/user/delete/"+id).success(function(respone){
               // $http.get("/api/user").success(function(response) {$scope.dataList = response;});
            });
        }
    });
</script>
</body>
</html>